package com.lb.rabbitmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class RabbitMQProducer {
    private static final String QUEUE_NAME = "example_queue";

    public static void main(String[] args) {
        // 创建连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost"); // RabbitMQ 服务器地址
        factory.setUsername("guest"); // 用户名
        factory.setPassword("guest"); // 密码

        try (
            // 创建连接和信道
            Connection connection = factory.newConnection();
            Channel channel = connection.createChannel()
        ) {
            // 声明队列
            channel.queueDeclare(QUEUE_NAME, true, false, false, null);

            // 要发送的消息
            String message = "[1,1,5000,0,78,110,0]";
            // 发布消息到队列
            channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
            System.out.println("Message sent: " + message);


        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
